package camid.services.nodemanager;

import camid.distribution.interceptor.InterceptorChain;
import camid.distribution.interceptor.InvocationInterceptor;
import camid.distribution.protocol.MethodRequestMessage;
import camid.distribution.protocol.MethodResponseMessage;

public class LoadAlertInterceptor implements InvocationInterceptor {

	public static final String LOAD_ALERT = "NodeLoadAlert";
	
	private INodeManager nodeManager;
	
	public LoadAlertInterceptor(INodeManager nodeManager) {
		this.nodeManager = nodeManager;
	}
	
	@Override
	public void beforeInvocation(MethodRequestMessage requestMessage)
			throws Exception {
		
		
	}

	@Override
	public void afterInvocation(MethodRequestMessage requestMessage,
			MethodResponseMessage responseMessage) throws Exception {
		
		
	}

	@Override
	public MethodResponseMessage intercept(InterceptorChain interceptorChain)
			throws Exception {
		
		MethodResponseMessage responseMsg = interceptorChain.proceed();
		Boolean alert = nodeManager.isUnderLoadAlert();
		if(alert != null) {
			responseMsg.getInvocationContext().put(LOAD_ALERT, alert);
		}
		return responseMsg;
	}

}
